package com.osstem;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 클래스설명 : DbManager
 * @version : 2011. 11. 14.
 * @author : jw
 * @분류 : 
 * 설명 : andorid sqlite db manager 
 * ChangeSystem / package com.osstem;
 */

public class DbHelper extends SQLiteOpenHelper {
	private static final String TB_STAFF_CREATE =
			  "create table tb_staff (sabun text primary key , "
			              		   + "name text not null);";
			     
	private static final String DATABASE_NAME = "data";
	private static final String DATABASE_TABLE = "tb_staff";
	private static final int DATABASE_VERSION = 2;
	

	public DbHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		// TODO Auto-generated constructor stub
	}

	
	@Override
	public void onCreate(SQLiteDatabase db) {
		//db.execSQL(TB_STAFF_CREATE);
		deleteAll(db);
		insertIintData(db);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL(TB_STAFF_CREATE);
	}
	
	
	/** 
	 * Method   : deleteAll
	 * 최초작성일  : 2011. 11. 14. 
	 * 작성자 : jw
	 * 변경이력 :  
	 * Method 설명 : 모든 테이블의 데이터를지운다. 
	 */
	public void deleteAll(SQLiteDatabase db){
		db.execSQL("drop table if exists tb_staff");
		db.execSQL("drop table if exists tb_insertamount");
	}
	
	
	/** 
	 * Method   : insertIintData
	 * 최초작성일  : 2011. 11. 14. 
	 * 작성자 : jw
	 * 변경이력 :  
	 * Method 설명 : 초기 필요한 데이터를 입력한다. 
	 */
	public void insertIintData(SQLiteDatabase db){
		db.execSQL("create table tb_insertamount (sabun text not null, date text not null, amount text not null ,primary key(sabun, date) );");
		db.execSQL("create table tb_staff (sabun text primary key , name text not null);");
		db.execSQL("insert into tb_staff (sabun, name) values ('04030901', '황승용');");
		db.execSQL("insert into tb_staff (sabun, name) values ('08010502', '심나미');");
		db.execSQL("insert into tb_staff (sabun, name) values ('11062601', '석민호');");
		db.execSQL("insert into tb_staff (sabun, name) values ('13062201', '이상준');");
		db.execSQL("insert into tb_staff (sabun, name) values ('14010403', '박민수');");
		db.execSQL("insert into tb_staff (sabun, name) values ('14010501', '이보람');");
		db.execSQL("insert into tb_staff (sabun, name) values ('14110103', '권희정');");
		db.execSQL("insert into tb_staff (sabun, name) values ('14120901', '정윤수');");
		db.execSQL("insert into tb_staff (sabun, name) values ('15070101', '강윤철');");
		db.execSQL("insert into tb_staff (sabun, name) values ('15101001', '이진우');");
		db.execSQL("insert into tb_staff (sabun, name) values ('p15101018', '유승옥');");
		db.execSQL("insert into tb_staff (sabun, name) values ('p14082601', '김남혁');");
	}
}
